<!DOCTYPE html>
<html>
<head>
	<!-- Google Tag Manager -->
	<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
	new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
	j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
	'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
	})(window,document,'script','dataLayer','GTM-W8KNPT4');</script>
	<!-- End Google Tag Manager -->
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width,inital-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,minimal-ui">
    <meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
	<meta name="format-detection" content="telephone=no">
    <title>登录 - 博猫体育</title>
    <link rel="stylesheet" href="css/login.css?ver=1.0.000">
    <link rel="stylesheet" href="css/iconfont.css?ver=1.0.000">
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>
    <script src="js/pageLib.js"></script>
</head>
<body>
<div class="header">
	<div class="title">登录</div>
	<div class="left-btn"><a href="javascript:window.history.go(-1);"><i class="iconfont icon-guanbi"></i></a></div>
	<div class="right-btn"></div>
</div>
<div class="page-content">
	<div class="logo"></div>
	<form class="input-wrapper">
		<div class="input-shell phone"><input type="text" name="username" placeholder="手机号" class=""></div>
		<div class="input-shell key last"><input type="password" name="password" placeholder="密码"><i href="#" class="control invisible"></i></div>
	</form>
	<a class="submit disable" href="javascript:;">登　录</a>
	<a class="question" href="reg.html"><span>还没有账号？</span>马上注册</a>
</div>

</body>
<script type="text/javascript">
	$(document).ready(function(){
		pageLib.initAffiliate();
		var analysisRequest=function(url){
			var args = {};
			var match = null;
			var search = decodeURIComponent(url.split('?')[1]);
			var reg = /(?:([^&]+)=([^&]+))/g;
			while((match = reg.exec(search))!==null){
				args[match[1]] = match[2];
			}
			return args;// Return the object
		};
		var fromUrl=pageLib.getQueryArgs(window.location.href).from;
		if(!!fromUrl)$('.question').attr('href','reg.html?from='+fromUrl);
		var apiBaseUrl='http://api.bybrain.cn';
		var username=$('.page-content .input-shell>input[name=username]');
		var password=$('.page-content .input-shell>input[name=password]');
		var submit=$('.page-content .submit');
		$('.page-content .control.invisible').on('click',function(e){
			if($(e.target).hasClass('visible')){
				$(e.target).removeClass('visible').prev('input[name=password]').attr('type','password');
			}
			else{
				$(e.target).addClass('visible').prev('input[name=password]').attr('type','text');
			}
		});//绑定密码可见按钮事件
		$('.page-content .input-shell>input').on('keyup',function(e){
			var mobileRegex=/^1[3-8]{1}[0-9]{9}$/;
			var passwordRegex=/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~\-\+]{1,20}$/;
			usernameOK=mobileRegex.test(username.val());
			passwordOK=passwordRegex.test(password.val());
			var submitFun=function(e){
					var timestamp=parseInt((new Date).getTime()/1000);
					if(!submit.hasClass('disable'))submit.off('click').addClass('disable').text('登录中...');
					pageLib.login({
						username: username.val().trim(),
						password: password.val().trim(),
						success: function(){
							submit.off('click').addClass('disable').text('登录成功，正在跳转...');
							if(!!fromUrl){
								window.location.href=fromUrl;
							}
							else{
								window.location.href='sporttery.html';
							}
						},
						failed: function(){
							submit.on('click',submitFun).removeClass('disable').text('登　录');
						}
					});
					/*
					 $.ajax({
						url:apiBaseUrl+'/v1/user/login',
						type:'GET',
						dataType:'json',
						data:{
							mobile:username.val().trim(),
							password:password.val().trim(),
							t:timestamp
						},
						beforeSend: function(){
							if(!submit.hasClass('disable'))submit.off('click').addClass('disable').text('登录中...');
							//app.showIndicator();
							//这里似乎不生效
						},
						complete:function(){
							//app.hideIndicator();
						},
						success: function(data){
							//console.log(data);
							if(data['status']==1){
								submit.off('click').addClass('disable').text('登录成功，正在跳转...');
								if(fromUrl){
									window.location.href=fromUrl;
								}
								else{
									window.location.href='/sporttery.html';
								}
							}
							else{
								alert(data.msg);
								submit.on('click',submitFun).removeClass('disable').text('登　录');
							}
						}
					 });
					*/
					//console.log(token);
					//登录函数
					//全局数据刷新函数
				};
			if(usernameOK && passwordOK){

				if(submit.hasClass('disable'))submit.removeClass('disable').off('click').on('click',submitFun);
			}
		});
	})
</script>
</html>